#include "tutorial.h"
#include "add.h"
#include "thr.h"
#include <stdio.h>

typedef int (*notifyFunc)(int *, int);

#define RET_FAIL -1
#define RET_SUCC 0

int notify(int *arr, int len)
{
    printf("notify begin!\n");
    int i;
    for (i = 0; i < len; i++) {
        printf("arr[%d] = %d\n", i, *(arr + i));
    }
    printf("notify over!\n");
    return RET_SUCC;
}

notifyFunc g_notify = NULL;

int declareAndNotify()
{
    int arr[7] = {1, 2, 3, 4, 5, 6};
    if (g_notify == NULL) {
        printf("NULL ptr func pointer!\n");
        return RET_FAIL;
    }
    g_notify(arr, 7);
    return RET_SUCC;
}

bool judge(int a, int b)
{
    if (a < b) {
        return true;
    }
    return false;
}

void regNotifyFunc(notifyFunc f)
{
    if (g_notify != NULL) {
        printf("duplicate func is assgin!\n");
    }
    g_notify = f;
    printf("reg succ!\n");
}

int main()
{
    printf("hello, world!\n");

    regNotifyFunc(notify);
    int ret = declareAndNotify();
    if (ret != RET_SUCC) {
        printf("declare fail!\n");
    }
    if (judge(3, 4)) {
        printf("3 < 4\n");
    }

    int a    = 0;
    int b    = 9;
    int de   = 90;
    int gh[] = {3, 5, 6, 9};
    printf("a + b = %d\n", add(3, 5));

    hello();

    return 0;
}
